package com.huawei.gamebox.plugin.gameservice.newsinfo.node;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.gamebox.plugin.gameservice.newsinfo.bean.NewsInfoWithTitleBean;
import com.huawei.gamebox.plugin.gameservice.newsinfo.card.NewsInfoCard;
import com.huawei.gamebox.plugin.gameservice.newsinfo.card.NewsInfoWithTitleCard;
import com.huawei.gamebox.service.common.cardkit.card.BaseGsCard;
import com.huawei.gamebox.service.common.cardkit.node.BaseGsNode;
import com.huawei.gamebox.service.welfare.common.card.GsTitleCard;
import java.util.List;
import o.azb;
import o.chy;
import o.chz;
import o.cih;
import o.CollectCheck;
import o.exp$e;
import o.exp.j;

public class NewsInfoWithTitleNode extends BaseGsNode {
    private chy ˊ;

    static class d implements OnClickListener {
        private final BaseGsCard ˊ;
        private final int ˋ;
        private final chy ॱ;

        d(chy o_chy, BaseGsCard baseGsCard, int i) {
            this.ॱ = o_chy;
            this.ˊ = baseGsCard;
            this.ˋ = i;
        }

        public void onClick(View view) {
            if (this.ॱ != null && this.ˊ != null) {
                this.ॱ.ˏ(this.ˋ, this.ˊ);
            }
        }
    }

    public NewsInfoWithTitleNode(Context context) {
        super(context);
    }

    public int ˏ() {
        return 1;
    }

    public boolean ॱ() {
        return true;
    }

    public boolean ˊ(ViewGroup viewGroup, ViewGroup viewGroup2) {
        LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
        layoutParams.weight = 1.0f;
        azb.ˏ(viewGroup);
        int ˏ = ˏ();
        LayoutInflater from = LayoutInflater.from(this.ॱ);
        new RelativeLayout.LayoutParams(-1, 1).setMargins(0, 0, 0, 0);
        for (int i = 0; i < ˏ; i++) {
            cih newsInfoWithTitleCard = new NewsInfoWithTitleCard(this.ॱ);
            View view = (LinearLayout) from.inflate(j.ˎ, null);
            newsInfoWithTitleCard.ˋ(view);
            GsTitleCard gsTitleCard = new GsTitleCard(this.ॱ);
            View inflate = from.inflate(j.ॱˊ, null);
            gsTitleCard.ˏ(inflate);
            newsInfoWithTitleCard.ˎ(gsTitleCard);
            view.addView(inflate);
            ˊ(newsInfoWithTitleCard);
            viewGroup.addView(view, layoutParams);
        }
        return true;
    }

    public boolean ॱ(chz o_chz, ViewGroup viewGroup) {
        int ˏ = ˏ();
        this.ˏ = o_chz.ˏ;
        for (int i = 0; i < ˏ; i++) {
            cih ˎ = ˎ(i);
            if (ˎ instanceof NewsInfoWithTitleCard) {
                NewsInfoWithTitleCard newsInfoWithTitleCard = (NewsInfoWithTitleCard) ˎ;
                CardBean ˋ = o_chz.ˋ(i);
                ˋ.ˋˋ(String.valueOf(this.ˏ));
                if (ˋ instanceof NewsInfoWithTitleBean) {
                    List ॱ = ((NewsInfoWithTitleBean) ˋ).ॱ();
                    if (CollectCheck.isEmpty(ॱ)) {
                        ˎ.ˉ().setVisibility(8);
                    } else {
                        ˊ(newsInfoWithTitleCard, ॱ.size());
                        ˎ.ˎ(ˋ, viewGroup);
                        ˎ.ˉ().setVisibility(0);
                    }
                } else {
                    ˎ.ˉ().setVisibility(8);
                }
            }
        }
        return true;
    }

    private void ˊ(NewsInfoWithTitleCard newsInfoWithTitleCard, int i) {
        LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
        layoutParams.weight = 1.0f;
        LayoutInflater from = LayoutInflater.from(this.ॱ);
        new RelativeLayout.LayoutParams(-1, 1).setMargins(0, 0, 0, 0);
        for (int i2 = 0; i2 < i; i2++) {
            View view = (ViewGroup) from.inflate(j.ˏॱ, null);
            BaseGsCard newsInfoCard = new NewsInfoCard(this.ॱ);
            view.setBackgroundResource(exp$e.ᐝ);
            newsInfoCard.ˏ(view);
            newsInfoWithTitleCard.ˋ(newsInfoCard);
            View ˉ = newsInfoWithTitleCard.ˉ();
            if (ˉ instanceof ViewGroup) {
                ((ViewGroup) ˉ).addView(view, layoutParams);
            }
        }
        ˋ(this.ˊ);
    }

    public void ˋ(chy o_chy) {
        this.ˊ = o_chy;
        for (int i = 0; i < ˊॱ(); i++) {
            NewsInfoWithTitleCard newsInfoWithTitleCard = (NewsInfoWithTitleCard) ˊ(i);
            if (newsInfoWithTitleCard != null) {
                newsInfoWithTitleCard.ˊ().ॱ(o_chy);
                for (int i2 = 0; i2 < newsInfoWithTitleCard.ˋ(); i2++) {
                    BaseGsCard ˊ = newsInfoWithTitleCard.ˊ(i2);
                    View view = null;
                    if (ˊ != null) {
                        view = ˊ.ˉ();
                    }
                    if (view != null) {
                        view.setOnClickListener(new d(o_chy, ˊ, 0));
                    }
                }
            }
        }
    }
}
